package com.cefa.edu.dao;

import java.util.HashMap;
import java.util.List;
import com.cefa.edu.datasource.DataSource;
import com.cefa.edu.model.EduStage;
import com.cefa.edu.model.StudentStageData;
import org.apache.ibatis.annotations.*;

/**
 * Created by cc664 on 2018/8/3.
 */
@Mapper
public interface EduStageMapper {

    //根据毕业年份、毕业生名称 获取对应的毕业生基础信息
    @Select({"SELECT s.user_id userId,u. NAME name,s.end_year graduateYear," +
            "s.stage_type stageId," +
            "s.grade_id gradeId," +
            "s.education_stage_name stageName," +
            "s.class_name className,s.grade_name gradeName FROM cefa_edu_user u,cefa_edu_student_stage_data s ${retrival} "})
    List<HashMap<String,Object>> getGraduates(@Param("retrival") String retrival);


    // 根据学生id 获取对应的学习阶段数据
    @DataSource("cefaedu")
    @Select({"select sd.user_id,sd.education_stage_name,sd.start_year,sd.level,sd.education_stage_id from cefa_edu_student_stage_data sd where sd.user_id=#{userId}"})
    @Results(id="stageMap",value={
            @Result(property ="userId" ,column = "user_id"),
            @Result(property = "stageName",column = "education_stage_name"),
            @Result(property ="startYear",column = "start_year"),
            @Result(property = "level",column = "level"),
            @Result(property = "eduStageId",column ="education_stage_id" )
    })
    public List<HashMap<String,Object>> getEduStageByUserId(Integer userId);

    @Update({ "update cefa_edu_student_stage_data set graduate=#{graduate},end_year=#{endYear}  where  stage_type =#{stageType} and grade_id=#{gradId}" })
    int updateStageData(@Param("graduate") Integer graduate,@Param("endYear")Integer endYear,@Param("stageType") Integer stageType,@Param("gradId") Integer gradId);

    @Delete("DELETE FROM cefa_edu_student_stage_data WHERE user_id = #{userId} and education_stage_id=#{educationStageId} ")
    void deleteEducationStage(@Param("userId") Integer userId,@Param("educationStageId") Integer educationStageId);

    @Select({"select graduate from cefa_edu_student_stage_data s where user_id=#{uId} and grade_id=#{gradeId}"})
    Integer getGraduateByStudentId(@Param("uId")Integer uId,@Param("gradeId")Integer gradeId);
}
